<?php
namespace Common\Model;
use Think\Model;
class TypeModel extends Model{
	protected $tableName="newstype";
	protected $connection="DB_CONFIG1";
	/**
	 * @desc 呈现下拉框
	 * @param string $currentTypeId 选中项的分类id
	 * @return string
	 * 
	 */
	function showOption($currentTypeId=''){
		//获取第一级分类
		$typeOneArr=$this->where("fid=0 and isshow=1")
						 ->select();
		$optionStr="";//下拉框中的option
		foreach($typeOneArr as $v){
			$optionStr.="<optgroup label='{$v['name']}'>";
			//获取当前一级分类下的子分类
			$typeTwoArr=$this->where("fid={$v['id']}")
							 ->select();
			foreach($typeTwoArr as $sv){
				if($sv['id']==$currentTypeId){
					$optionStr.="<option selected='selected' value='{$v['id']}|{$sv['id']}'>{$sv['name']}</option>";
				}else{
					$optionStr.="<option value='{$v['id']}|{$sv['id']}'>{$sv['name']}</option>";
				}
			}
			$optionStr.="</optgroup>";
		}
		return $optionStr;
	}	
}